*** Appendix tables

clear all
set more off
set maxvar 20000
** note: type your directory here
global dir_dest "/replication/Data/"
global dir_dest_figures "/replication/Figures/"
global dir_dest_tables "/replication/Tables/" 

***********************************************************************************************************
// Table A1. Summary of the number of regulations
***********************************************************************************************************

use ${dir_dest}1_regulation_coding.dta,clear
count
tab ct
tab ct if score_h!=. & score_g!=. & scorehc!=.
tab ct if scorenlp!=.

count if ct==1 & year>=1978 & year<=1995
count if ct==1 & year>1995 & year<=2001
count if ct==1 & year>2001 & year<=2007

***********************************************************************************************************
// Table A2. Cross tabulation of random forest coding and manual coding
***********************************************************************************************************

use ${dir_dest}1_regulation_coding.dta,clear
tab scorehc scorerf

***********************************************************************************************************
// Table A3. Comparing results from the three NLP methods
***********************************************************************************************************

use ${dir_dest}1_regulation_coding.dta,clear
corr score_h score_g scorehc
corr score_h score_g scorehc if ct==1

corr score_sum scorerf scoremlp scorecnn if score_h!=.
corr scorehc scorerf scoremlp scorecnn if score_h!=.
corr scorehc scorerf scoremlp scorecnn
corr score_sum scorerf scoremlp scorecnn
count if score_sum==scorerf
count if score_sum==scoremlp
count if score_sum==scorecnn

set more off
use ${dir_dest}2_main_regression.dta,clear
keep if year==2001
corr d_lhc d_lnlp d_lrf d_lmlp d_lcnn


***********************************************************************************************************
// Table A4. Descriptive statistics on migrant-related regulations from 1995 to 2007
***********************************************************************************************************

set more off
use ${dir_dest}1_regulation_coding.dta,clear
keep if year<=2007
keep if ct==1
gen n=1
gen x=1 if year<=1995
replace x=2 if year>1995 & year<=2001
replace x=3 if year>2001


sum n if x==3
sum scorehc if x==3
tab citygb if x==3,nof
dis r(r)
tab citygb if x==3 & scorehc>0,nof
dis r(r)
tab citygb if x==3 & scorehc==0,nof
dis r(r)
tab citygb if x==3 & scorehc<0,nof
dis r(r)

sum n if x==3 & cat=="Work"
sum scorehc if x==3 & cat=="Work"
tab citygb if x==3 & cat=="Work",nof
dis r(r)
tab citygb if x==3 & scorehc>0 & cat=="Work",nof
dis r(r)
tab citygb if x==3 & scorehc==0 & cat=="Work",nof
dis r(r)
tab citygb if x==3 & scorehc<0 & cat=="Work",nof
dis r(r)

sum n if x==3 & cat=="Local public goods"
sum scorehc if x==3 & cat=="Local public goods"
tab citygb if x==3 & cat=="Local public goods",nof
dis r(r)
tab citygb if x==3 & scorehc>0 & cat=="Local public goods",nof
dis r(r)
tab citygb if x==3 & scorehc==0 & cat=="Local public goods",nof
dis r(r)
tab citygb if x==3 & scorehc<0 & cat=="Local public goods",nof
dis r(r)

sum n if x==3 & cat=="Social insurance"
sum scorehc if x==3 & cat=="Social insurance"
tab citygb if x==3 & cat=="Social insurance",nof
dis r(r)
tab citygb if x==3 & scorehc>0 & cat=="Social insurance",nof
dis r(r)
tab citygb if x==3 & scorehc==0 & cat=="Social insurance",nof
dis r(r)
tab citygb if x==3 & scorehc<0 & cat=="Social insurance",nof
dis r(r)


sum n if x==3 & cat=="Family planning"
sum scorehc if x==3 & cat=="Family planning"
tab citygb if x==3 & cat=="Family planning",nof
dis r(r)
tab citygb if x==3 & scorehc>0 & cat=="Family planning",nof
dis r(r)
tab citygb if x==3 & scorehc==0 & cat=="Family planning",nof
dis r(r)
tab citygb if x==3 & scorehc<0 & cat=="Family planning",nof
dis r(r)


sum n if x==3 & cat=="Hukou"
sum scorehc if x==3 & cat=="Hukou"
tab citygb if x==3 & cat=="Hukou",nof
dis r(r)
tab citygb if x==3 & scorehc>0 & cat=="Hukou",nof
dis r(r)
tab citygb if x==3 & scorehc==0 & cat=="Hukou",nof
dis r(r)
tab citygb if x==3 & scorehc<0 & cat=="Hukou",nof
dis r(r)


sum n if x==3 & cat=="Other"
sum scorehc if x==3 & cat=="Other"
tab citygb if x==3 & cat=="Other",nof
dis r(r)
tab citygb if x==3 & scorehc>0 & cat=="Other",nof
dis r(r)
tab citygb if x==3 & scorehc==0 & cat=="Other",nof
dis r(r)
tab citygb if x==3 & scorehc<0 & cat=="Other",nof
dis r(r)

sum n if x==2
sum scorehc if x==2
tab citygb if x==2,nof
dis r(r)
tab citygb if x==2 & scorehc>0,nof
dis r(r)
tab citygb if x==2 & scorehc==0,nof
dis r(r)
tab citygb if x==2 & scorehc<0,nof
dis r(r)

sum n if x==2 & cat=="Work"
sum scorehc if x==2 & cat=="Work"
tab citygb if x==2 & cat=="Work",nof
dis r(r)
tab citygb if x==2 & scorehc>0 & cat=="Work",nof
dis r(r)
tab citygb if x==2 & scorehc==0 & cat=="Work",nof
dis r(r)
tab citygb if x==2 & scorehc<0 & cat=="Work",nof
dis r(r)

sum n if x==2 & cat=="Local public goods"
sum scorehc if x==2 & cat=="Local public goods"
tab citygb if x==2 & cat=="Local public goods",nof
dis r(r)
tab citygb if x==2 & scorehc>0 & cat=="Local public goods",nof
dis r(r)
tab citygb if x==2 & scorehc==0 & cat=="Local public goods",nof
dis r(r)
tab citygb if x==2 & scorehc<0 & cat=="Local public goods",nof
dis r(r)

sum n if x==2 & cat=="Social insurance"
sum scorehc if x==2 & cat=="Social insurance"
tab citygb if x==2 & cat=="Social insurance",nof
dis r(r)
tab citygb if x==2 & scorehc>0 & cat=="Social insurance",nof
dis r(r)
tab citygb if x==2 & scorehc==0 & cat=="Social insurance",nof
dis r(r)
tab citygb if x==2 & scorehc<0 & cat=="Social insurance",nof
dis r(r)


sum n if x==2 & cat=="Family planning"
sum scorehc if x==2 & cat=="Family planning"
tab citygb if x==2 & cat=="Family planning",nof
dis r(r)
tab citygb if x==2 & scorehc>0 & cat=="Family planning",nof
dis r(r)
tab citygb if x==2 & scorehc==0 & cat=="Family planning",nof
dis r(r)
tab citygb if x==2 & scorehc<0 & cat=="Family planning",nof
dis r(r)


sum n if x==2 & cat=="Hukou"
sum scorehc if x==2 & cat=="Hukou"
tab citygb if x==2 & cat=="Hukou",nof
dis r(r)
tab citygb if x==2 & scorehc>0 & cat=="Hukou",nof
dis r(r)
tab citygb if x==2 & scorehc==0 & cat=="Hukou",nof
dis r(r)
tab citygb if x==2 & scorehc<0 & cat=="Hukou",nof
dis r(r)


sum n if x==2 & cat=="Other"
sum scorehc if x==2 & cat=="Other"
tab citygb if x==2 & cat=="Other",nof
dis r(r)
tab citygb if x==2 & scorehc>0 & cat=="Other",nof
dis r(r)
tab citygb if x==2 & scorehc==0 & cat=="Other",nof
dis r(r)
tab citygb if x==2 & scorehc<0 & cat=="Other",nof
dis r(r)

sum n if x==1
sum scorehc if x==1
tab citygb if x==1,nof
dis r(r)
tab citygb if x==1 & scorehc>0,nof
dis r(r)
tab citygb if x==1 & scorehc==0,nof
dis r(r)
tab citygb if x==1 & scorehc<0,nof
dis r(r)

sum n if x==1 & cat=="Work"
sum scorehc if x==1 & cat=="Work"
tab citygb if x==1 & cat=="Work",nof
dis r(r)
tab citygb if x==1 & scorehc>0 & cat=="Work",nof
dis r(r)
tab citygb if x==1 & scorehc==0 & cat=="Work",nof
dis r(r)
tab citygb if x==1 & scorehc<0 & cat=="Work",nof
dis r(r)

sum n if x==1 & cat=="Local public goods"
sum scorehc if x==1 & cat=="Local public goods"
tab citygb if x==1 & cat=="Local public goods",nof
dis r(r)
tab citygb if x==1 & scorehc>0 & cat=="Local public goods",nof
dis r(r)
tab citygb if x==1 & scorehc==0 & cat=="Local public goods",nof
dis r(r)
tab citygb if x==1 & scorehc<0 & cat=="Local public goods",nof
dis r(r)

sum n if x==1 & cat=="Social insurance"
sum scorehc if x==1 & cat=="Social insurance"
tab citygb if x==1 & cat=="Social insurance",nof
dis r(r)
tab citygb if x==1 & scorehc>0 & cat=="Social insurance",nof
dis r(r)
tab citygb if x==1 & scorehc==0 & cat=="Social insurance",nof
dis r(r)
tab citygb if x==1 & scorehc<0 & cat=="Social insurance",nof
dis r(r)


sum n if x==1 & cat=="Family planning"
sum scorehc if x==1 & cat=="Family planning"
tab citygb if x==1 & cat=="Family planning",nof
dis r(r)
tab citygb if x==1 & scorehc>0 & cat=="Family planning",nof
dis r(r)
tab citygb if x==1 & scorehc==0 & cat=="Family planning",nof
dis r(r)
tab citygb if x==1 & scorehc<0 & cat=="Family planning",nof
dis r(r)


sum n if x==1 & cat=="Hukou"
sum scorehc if x==1 & cat=="Hukou"
tab citygb if x==1 & cat=="Hukou",nof
dis r(r)
tab citygb if x==1 & scorehc>0 & cat=="Hukou",nof
dis r(r)
tab citygb if x==1 & scorehc==0 & cat=="Hukou",nof
dis r(r)
tab citygb if x==1 & scorehc<0 & cat=="Hukou",nof
dis r(r)


sum n if x==1 & cat=="Other"
sum scorehc if x==1 & cat=="Other"
tab citygb if x==1 & cat=="Other",nof
dis r(r)
tab citygb if x==1 & scorehc>0 & cat=="Other",nof
dis r(r)
tab citygb if x==1 & scorehc==0 & cat=="Other",nof
dis r(r)
tab citygb if x==1 & scorehc<0 & cat=="Other",nof
dis r(r)


***********************************************************************************************************
// Table C1. Effects of changes in tariffs on exports on changes in regulation scores, 2001–2007, using 3 NLP measures separately.
***********************************************************************************************************

// Table C1 Panel A. Main results, all three

set more off
use ${dir_dest}2_main_regression.dta,clear
keep if year==2001

set more off
reg d_lnlp tf_exp_wage tf_imp_wage tf_m_wage lnlp_st if year==2001 , cluster(provgb)
sum d_lnlp 
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_nlp.tex,replace dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lnlp tf_exp_wage tf_imp_wage tf_m_wage lnlp_st pntr_us DT  exp_pre imp_pre m_pre if year==2001 , cluster(provgb)
sum d_lnlp 
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_nlp.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lnlp tf_exp_wage tf_imp_wage tf_m_wage lnlp_st  if year==2001 & lambda13<=.0548622, cluster(provgb)
sum d_lnlp if lambda13<=.0548622
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage if lambda13<=.0548622
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_nlp.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lnlp tf_exp_wage tf_imp_wage tf_m_wage lnlp_st  pntr_us DT  exp_pre imp_pre m_pre if year==2001 & lambda13<=.0548622, cluster(provgb)
sum d_lnlp if lambda13<=.0548622
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage if lambda13<=.0548622
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_nlp.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lnlp tf_exp_wage tf_imp_wage tf_m_wage lnlp_st if year==2001 & lambda13<=.0548622 & d_l_gdppct!=., cluster(provgb)
sum d_lnlp if lambda13<=.0548622 & d_l_gdppct!=.
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage if lambda13<=.0548622 & d_l_gdppct!=.
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_nlp.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lnlp tf_exp_wage tf_imp_wage tf_m_wage lnlp_st pntr_us DT exp_pre imp_pre m_pre if year==2001 & lambda13<=.0548622 & d_l_gdppct!=., cluster(provgb)
sum d_lnlp if lambda13<=.0548622 & d_l_gdppct!=.
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage if lambda13<=.0548622 & d_l_gdppct!=.
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_nlp.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lnlp tf_exp_wage tf_imp_wage tf_m_wage lnlp_st pntr_us DT  exp_pre imp_pre m_pre wage_lag gdppct_lag if year==2001 & lambda13<=.0548622, cluster(provgb)
sum d_lnlp if lambda13<=.0548622 & d_l_gdppct!=. & gdppct_lag!=.
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage if lambda13<=.0548622 & d_l_gdppct!=. & gdppct_lag!=.
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_nlp.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')



// Table C1 Panel B. Main results, MLP

set more off
reg d_lmlp tf_exp_wage tf_imp_wage tf_m_wage lmlp_st if year==2001 , cluster(provgb)
sum d_lmlp 
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_mlp.tex,replace dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lmlp tf_exp_wage tf_imp_wage tf_m_wage lmlp_st pntr_us DT  exp_pre imp_pre m_pre if year==2001 , cluster(provgb)
sum d_lmlp 
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_mlp.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lmlp tf_exp_wage tf_imp_wage tf_m_wage lmlp_st  if year==2001 & lambda13<=.0548622, cluster(provgb)
sum d_lmlp if lambda13<=.0548622
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage if lambda13<=.0548622
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_mlp.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lmlp tf_exp_wage tf_imp_wage tf_m_wage lmlp_st  pntr_us DT  exp_pre imp_pre m_pre if year==2001 & lambda13<=.0548622, cluster(provgb)
sum d_lmlp if lambda13<=.0548622
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage if lambda13<=.0548622
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_mlp.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lmlp tf_exp_wage tf_imp_wage tf_m_wage lmlp_st if year==2001 & lambda13<=.0548622 & d_l_gdppct!=., cluster(provgb)
sum d_lmlp if lambda13<=.0548622 & d_l_gdppct!=.
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage if lambda13<=.0548622 & d_l_gdppct!=.
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_mlp.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lmlp tf_exp_wage tf_imp_wage tf_m_wage lmlp_st pntr_us DT exp_pre imp_pre m_pre if year==2001 & lambda13<=.0548622 & d_l_gdppct!=., cluster(provgb)
sum d_lmlp if lambda13<=.0548622 & d_l_gdppct!=.
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage if lambda13<=.0548622 & d_l_gdppct!=.
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_mlp.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lmlp tf_exp_wage tf_imp_wage tf_m_wage lmlp_st pntr_us DT  exp_pre imp_pre m_pre wage_lag gdppct_lag if year==2001 & lambda13<=.0548622, cluster(provgb)
sum d_lmlp if lambda13<=.0548622 & d_l_gdppct!=. & gdppct_lag!=.
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage if lambda13<=.0548622 & d_l_gdppct!=. & gdppct_lag!=.
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_mlp.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')

// Table C1 Panel C. Main results, CNN

set more off
reg d_lcnn tf_exp_wage tf_imp_wage tf_m_wage lcnn_st if year==2001 , cluster(provgb)
sum d_lcnn 
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_cnn.tex,replace dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lcnn tf_exp_wage tf_imp_wage tf_m_wage lcnn_st pntr_us DT  exp_pre imp_pre m_pre if year==2001 , cluster(provgb)
sum d_lcnn 
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_cnn.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lcnn tf_exp_wage tf_imp_wage tf_m_wage lcnn_st  if year==2001 & lambda13<=.0548622, cluster(provgb)
sum d_lcnn if lambda13<=.0548622
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage if lambda13<=.0548622
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_cnn.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lcnn tf_exp_wage tf_imp_wage tf_m_wage lcnn_st  pntr_us DT  exp_pre imp_pre m_pre if year==2001 & lambda13<=.0548622, cluster(provgb)
sum d_lcnn if lambda13<=.0548622
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage if lambda13<=.0548622
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_cnn.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lcnn tf_exp_wage tf_imp_wage tf_m_wage lcnn_st if year==2001 & lambda13<=.0548622 & d_l_gdppct!=., cluster(provgb)
sum d_lcnn if lambda13<=.0548622 & d_l_gdppct!=.
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage if lambda13<=.0548622 & d_l_gdppct!=.
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_cnn.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lcnn tf_exp_wage tf_imp_wage tf_m_wage lcnn_st pntr_us DT exp_pre imp_pre m_pre if year==2001 & lambda13<=.0548622 & d_l_gdppct!=., cluster(provgb)
sum d_lcnn if lambda13<=.0548622 & d_l_gdppct!=.
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage if lambda13<=.0548622 & d_l_gdppct!=.
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_cnn.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')
reg d_lcnn tf_exp_wage tf_imp_wage tf_m_wage lcnn_st pntr_us DT  exp_pre imp_pre m_pre wage_lag gdppct_lag if year==2001 & lambda13<=.0548622, cluster(provgb)
sum d_lcnn if lambda13<=.0548622 & d_l_gdppct!=. & gdppct_lag!=.
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage if lambda13<=.0548622 & d_l_gdppct!=. & gdppct_lag!=.
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 using ${dir_dest_tables}main_cnn.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx')




***********************************************************************************************************
// Table C2. Effects of changes in tariffs on exports on changes in regulation scores, 2001–2007, using panel
***********************************************************************************************************

set more off
use ${dir_dest}2_main_regression.dta,clear
keep if lambda13<=.0548622
drop if d_l_gdppct==.

sum d_lhc d_lrf tf_exp_wage if year==2001 & tf_exp_wage!=.	 & exp_pre!=. & gdppct_lag!=.
sum d_lhc d_lrf tf_exp_wage if year==1995 & tf_exp_wage!=.	 & tf_m_wage!=.

set more off
reghdfe d_lhc i.year##c.tf_exp_wage i.year##c.tf_imp_wage i.year##c.tf_m_wage lhc_st,a(citygb year) cluster(provgb)
outreg2 using ${dir_dest_tables}app_panel.tex,replace dec(2)
reghdfe d_lhc i.year##c.tf_exp_wage i.year##c.tf_imp_wage i.year##c.tf_m_wage lhc_st l_gdppct_st,a(citygb year) cluster(provgb)
outreg2 using ${dir_dest_tables}app_panel.tex,append dec(2)
reghdfe d_lhc i.year##c.tf_exp_wage i.year##c.tf_imp_wage i.year##c.tf_m_wage lhc_st l_gdppct_st l_wage_st,a(citygb year) cluster(provgb)
outreg2 using ${dir_dest_tables}app_panel.tex,append dec(2)
reghdfe d_lhc i.year##c.tf_exp_wage i.year##c.tf_imp_wage i.year##c.tf_m_wage lhc_st l_gdppct_st l_wage_st l_totpop_st,a(citygb year) cluster(provgb)
outreg2 using ${dir_dest_tables}app_panel.tex,append dec(2)
reghdfe d_lrf i.year##c.tf_exp_wage i.year##c.tf_imp_wage i.year##c.tf_m_wage lrf_st,a(citygb year) cluster(provgb)
outreg2 using ${dir_dest_tables}app_panel.tex,append dec(2)
reghdfe d_lrf i.year##c.tf_exp_wage i.year##c.tf_imp_wage i.year##c.tf_m_wage lrf_st l_gdppct_st,a(citygb year) cluster(provgb)
outreg2 using ${dir_dest_tables}app_panel.tex,append dec(2)
reghdfe d_lrf i.year##c.tf_exp_wage i.year##c.tf_imp_wage i.year##c.tf_m_wage lrf_st l_gdppct_st l_wage_st,a(citygb year) cluster(provgb)
outreg2 using ${dir_dest_tables}app_panel.tex,append dec(2)
reghdfe d_lrf i.year##c.tf_exp_wage i.year##c.tf_imp_wage i.year##c.tf_m_wage lrf_st l_gdppct_st l_wage_st l_totpop_st,a(citygb year) cluster(provgb)
outreg2 using ${dir_dest_tables}app_panel.tex,append dec(2)

***********************************************************************************************************
// Table C3. Effects of changes in tariffs on exports on changes in regulation scores, 2001–2007, using levels
***********************************************************************************************************

set more off
use ${dir_dest}2_main_regression.dta,clear

// column 1 
keep if year==2001
drop if tf_m_wage==.
reg d_scorehc tf_exp_wage tf_imp_wage tf_m_wage scorehc_st if year==2001 , cluster(provgb)
est store col1
boottest tf_exp_wage,cluster(provgb) rep(1000) seed(9)
local pb=`r(p)'
reg_ss d_scorehc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(1) control_varlist(tf_m_wage tf_imp_wage scorehc_st)
local p1=round(`e(p)',0.001)
reg_ss d_scorehc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(0) control_varlist(tf_m_wage tf_imp_wage scorehc_st)
local p0=round(`e(p)',0.001)
sum d_scorehc
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col1] using ${dir_JMP_v3}app_level_hc.tex,replace dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx', Bootstrap, `pb', AKM1, `p1', AKM0, `p0') label
// column 2
reg d_scorehc tf_exp_wage tf_imp_wage tf_m_wage scorehc_st pntr_us DT exp_pre imp_pre m_pre if year==2001 , cluster(provgb)
est store col2
boottest tf_exp_wage,cluster(provgb) rep(1000) seed(9)
local pb=`r(p)'
reg_ss d_scorehc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(1) control_varlist(tf_imp_wage tf_m_wage scorehc_st pntr_us DT exp_pre imp_pre m_pre)
local p1=round(`e(p)',0.001)
reg_ss d_scorehc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(0) control_varlist(tf_imp_wage tf_m_wage scorehc_st pntr_us DT exp_pre imp_pre m_pre)
local p0=round(`e(p)',0.001)
sum d_scorehc
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col2] using ${dir_JMP_v3}app_level_hc.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx', Bootstrap, `pb', AKM1, `p1', AKM0, `p0') label

// column 3
keep if lambda13<=.0548622
reg d_scorehc tf_exp_wage tf_imp_wage tf_m_wage scorehc_st if year==2001 & lambda13<=.0548622, cluster(provgb)
est store col3
boottest tf_exp_wage,cluster(provgb) rep(1000) seed(9)
local pb=`r(p)'
reg_ss d_scorehc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(1) control_varlist(tf_m_wage tf_imp_wage scorehc_st)
local p1=round(`e(p)',0.001)
reg_ss d_scorehc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(0) control_varlist(tf_m_wage tf_imp_wage scorehc_st)
local p0=round(`e(p)',0.001)
sum d_scorehc
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col3] using ${dir_JMP_v3}app_level_hc.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx', Bootstrap, `pb', AKM1, `p1', AKM0, `p0') label
// column 4
reg d_scorehc tf_exp_wage tf_imp_wage tf_m_wage scorehc_st pntr_us DT exp_pre imp_pre m_pre if year==2001 & lambda13<=.0548622, cluster(provgb)
est store col4
boottest tf_exp_wage,cluster(provgb) rep(1000) seed(9)
local pb=`r(p)'
reg_ss d_scorehc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(1) control_varlist(tf_imp_wage tf_m_wage scorehc_st pntr_us DT exp_pre imp_pre m_pre)
local p1=round(`e(p)',0.001)
reg_ss d_scorehc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(0) control_varlist(tf_imp_wage tf_m_wage scorehc_st pntr_us DT exp_pre imp_pre m_pre)
local p0=round(`e(p)',0.001)
sum d_scorehc
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col4] using ${dir_JMP_v3}app_level_hc.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx', Bootstrap, `pb', AKM1, `p1', AKM0, `p0') label
// column 5
keep if d_l_gdppct!=.
reg d_scorehc tf_exp_wage tf_imp_wage tf_m_wage scorehc_st if year==2001 & lambda13<=.0548622 & d_l_gdppct!=., cluster(provgb)
est store col5
boottest tf_exp_wage,cluster(provgb) rep(1000) seed(9)
local pb=`r(p)'
reg_ss d_scorehc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(1) control_varlist(tf_m_wage tf_imp_wage scorehc_st)
local p1=round(`e(p)',0.001)
reg_ss d_scorehc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(0) control_varlist(tf_m_wage tf_imp_wage scorehc_st)
local p0=round(`e(p)',0.001)
sum d_scorehc
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col5] using ${dir_JMP_v3}app_level_hc.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx', Bootstrap, `pb', AKM1, `p1', AKM0, `p0') label
// column 6
reg d_scorehc tf_exp_wage tf_imp_wage tf_m_wage scorehc_st pntr_us DT exp_pre imp_pre m_pre if year==2001 & lambda13<=.0548622, cluster(provgb)
est store col6
boottest tf_exp_wage,cluster(provgb) rep(1000) seed(9)
local pb=`r(p)'
reg_ss d_scorehc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(1) control_varlist( tf_imp_wage tf_m_wage scorehc_st pntr_us DT exp_pre imp_pre m_pre)
local p1=round(`e(p)',0.001)
reg_ss d_scorehc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(0) control_varlist( tf_imp_wage tf_m_wage scorehc_st pntr_us DT exp_pre imp_pre m_pre)
local p0=round(`e(p)',0.001)
sum d_scorehc
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col6] using ${dir_JMP_v3}app_level_hc.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx', Bootstrap, `pb', AKM1, `p1', AKM0, `p0') label
// column 7
keep if wage_lag!=. & gdppct_lag!=.
reg d_scorehc tf_exp_wage tf_imp_wage tf_m_wage scorehc_st pntr_us DT exp_pre imp_pre m_pre wage_lag gdppct_lag if year==2001 & lambda13<=.0548622, cluster(provgb)
est store col7
boottest tf_exp_wage,cluster(provgb) rep(1000) seed(9)
local pb=`r(p)'
reg_ss d_scorehc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(1) control_varlist(tf_imp_wage tf_m_wage scorehc_st pntr_us DT exp_pre imp_pre m_pre wage_lag gdppct_lag)
local p1=round(`e(p)',0.001)
reg_ss d_scorehc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(0) control_varlist(tf_imp_wage tf_m_wage scorehc_st pntr_us DT exp_pre imp_pre m_pre wage_lag gdppct_lag)
local p0=round(`e(p)',0.001)
sum d_scorehc
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col7] using ${dir_JMP_v3}app_level_hc.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx', Bootstrap, `pb', AKM1, `p1', AKM0, `p0') label


// Panel B. Main results, random forest coding

set more off
use ${dir_dest}2_main_regression.dta,clear
keep if year==2001

set more off
reg d_scorerf tf_exp_wage tf_imp_wage tf_m_wage scorerf_st if year==2001 , cluster(provgb)
sum d_scorerf
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_level_rf.tex,replace dec(2) addtext(Mean y, `my', Sd y, `sdy')
reg d_scorerf tf_exp_wage tf_imp_wage tf_m_wage scorerf_st pntr_us DT  exp_pre imp_pre m_pre if year==2001 , cluster(provgb)
sum d_scorerf
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_level_rf.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy')
reg d_scorerf tf_exp_wage tf_imp_wage tf_m_wage scorerf_st  if year==2001 & lambda13<=.0548622, cluster(provgb)
sum d_scorerf if lambda13<=.0548622
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_level_rf.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy')
reg d_scorerf tf_exp_wage tf_imp_wage tf_m_wage scorerf_st  pntr_us DT  exp_pre imp_pre m_pre if year==2001 & lambda13<=.0548622, cluster(provgb)
outreg2 using ${dir_dest_tables}app_level_rf.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy')
reg d_scorerf tf_exp_wage tf_imp_wage tf_m_wage scorerf_st if year==2001 & lambda13<=.0548622 & d_l_gdppct!=., cluster(provgb)
sum d_scorerf if lambda13<=.0548622 & d_l_gdppct!=.
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_level_rf.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy')
reg d_scorerf tf_exp_wage tf_imp_wage tf_m_wage scorerf_st pntr_us DT exp_pre imp_pre m_pre if year==2001 & lambda13<=.0548622 & d_l_gdppct!=., cluster(provgb)
sum d_scorerf if lambda13<=.0548622 & d_l_gdppct!=.
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_level_rf.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy')
reg d_scorerf tf_exp_wage tf_imp_wage tf_m_wage scorerf_st pntr_us DT  exp_pre imp_pre m_pre wage_lag gdppct_lag if year==2001 & lambda13<=.0548622, cluster(provgb)
sum d_scorerf if lambda13<=.0548622 & d_l_gdppct!=. & gdppct_lag!=.
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_level_rf.tex,append dec(2)  addtext(Mean y, `my', Sd y, `sdy')


***********************************************************************************************************
// Table C4. The effects of changes in tariffs on exports on changes in regulation score, using alternative measure of regulation changes
***********************************************************************************************************

set more off
use ${dir_dest}2_main_regression.dta,clear
keep if year==2001
keep if lambda13<=.0548622 & d_l_gdppct!=.

set more off
reg d_lhc tf_exp_wage tf_imp_wage tf_m_wage lhc  if year==2001, cluster(provgb)
sum d_lhc
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_pn.tex,replace dec(2)  addtext(Mean y, `my', Sd y, `sdy')
reg d_lpn tf_exp_wage tf_imp_wage tf_m_wage lpn_st  if year==2001, cluster(provgb)
sum d_lpn
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_pn.tex,append dec(2)   addtext(Mean y, `my', Sd y, `sdy')
reg d_lreg tf_exp_wage tf_imp_wage tf_m_wage lreg_st  if year==2001, cluster(provgb)
sum d_lreg
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_pn.tex,append dec(2)   addtext(Mean y, `my', Sd y, `sdy')
reg d_lwk tf_exp_wage tf_imp_wage tf_m_wage lwk_st  if year==2001, cluster(provgb)
sum d_lwk
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_pn.tex,append dec(2)   addtext(Mean y, `my', Sd y, `sdy')
reg d_lwf tf_exp_wage tf_imp_wage tf_m_wage lwf_st  if year==2001, cluster(provgb)
sum d_lwf
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_pn.tex,append dec(2)   addtext(Mean y, `my', Sd y, `sdy')
reg d_lhk tf_exp_wage tf_imp_wage tf_m_wage lhk_st  if year==2001, cluster(provgb)
sum d_lhk
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_pn.tex,append dec(2)   addtext(Mean y, `my', Sd y, `sdy')
reg d_lin tf_exp_wage tf_imp_wage tf_m_wage lin_st  if year==2001, cluster(provgb)
sum d_lin
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_pn.tex,append dec(2)   addtext(Mean y, `my', Sd y, `sdy')
reg d_loth tf_exp_wage tf_imp_wage tf_m_wage loth_st  if year==2001, cluster(provgb)
sum d_loth
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_pn.tex,append dec(2)   addtext(Mean y, `my', Sd y, `sdy')


***********************************************************************************************************
// Table C5. The effects of changes in tariffs on exports on changes in regulation score, using market-access-based trade shocks
***********************************************************************************************************

set more off
use ${dir_dest}2_main_regression.dta,clear
keep if year==2001
keep if lambda13<=.0548622 & d_l_gdppct!=.

set more off
sum d_lhc tf_exp_wage tf_exp_inc exp_ADH exp_ADH_GDP exp_ADH_gravity if year==2001

reg d_lhc tf_exp_wage tf_imp_wage tf_m_wage lhc_st  if year==2001, cluster(provgb)
outreg2 using ${dir_dest_tables}app_adh.tex,replace dec(2) 
reg d_lhc tf_exp_inc tf_imp_inc tf_m_inc lhc_st  if year==2001, cluster(provgb)
outreg2 using ${dir_dest_tables}app_adh.tex,append dec(2)    
reg d_lhc exp_ADH  if year==2001, cluster(provgb)
outreg2 using ${dir_dest_tables}app_adh.tex,append dec(2) 
reg d_lhc exp_ADH imp_ADH m_ADH if year==2001, cluster(provgb)
outreg2 using ${dir_dest_tables}app_adh.tex,append dec(2) 
reg d_lhc exp_ADH imp_ADH m_ADH lhc_st urban_st if year==2001, cluster(provgb)
outreg2 using ${dir_dest_tables}app_adh.tex,append dec(2) 
ivreg2 d_lhc (exp_ADH=exp_ADH_GDP) imp_ADH m_ADH lhc_st urban_st if year==2001, cluster(provgb) first
outreg2 using ${dir_dest_tables}app_adh.tex,append dec(2) 
ivreg2 d_lhc (exp_ADH=exp_ADH_gravity) imp_ADH m_ADH lhc_st urban_st if year==2001, cluster(provgb) first
outreg2 using ${dir_dest_tables}app_adh.tex,append dec(2) 

xtile pct=exp_ADH, n(3)
bysort pct: sum exp_ADH

***********************************************************************************************************
// Table C6. Competition between prefectures, geographic proximity
***********************************************************************************************************

set more off
use ${dir_dest}2_main_regression.dta,clear
keep if year==2001
keep if lambda13<=.0548622
keep if d_l_gdppct!=.

***first, check if trade shocks and regulation changes in the same province
***  affect own regulation change
set more off
reg d_lhc tf_exp_wage tf_imp_wage tf_m_wage  lhc_st  if year==2001 , cluster(provgb)
outreg2 using ${dir_dest_tables}app_comp_dist.tex,replace dec(2)
reg d_lhc tf_exp_wage tf_imp_wage tf_m_wage tf_exp_wage_pv_1  lhc_st  if year==2001 , cluster(provgb)
outreg2 using ${dir_dest_tables}app_comp_dist.tex,append dec(2)
reg d_lhc d_lhc_pv_1 tf_exp_wage tf_imp_wage tf_m_wage  lhc_st  if year==2001 , cluster(provgb)
outreg2 using ${dir_dest_tables}app_comp_dist.tex,append dec(2)
reg d_lhc d_lhc_pv_1 tf_exp_wage tf_imp_wage tf_m_wage tf_exp_wage_pv_1  lhc_st  if year==2001 , cluster(provgb)
outreg2 using ${dir_dest_tables}app_comp_dist.tex,append dec(2)
*** check if tf and reg change in nearby 5 cities affect own regulation change
reg d_lhc dist_tf_exp_wage tf_exp_wage tf_imp_wage tf_m_wage  lhc_st  if year==2001 , cluster(provgb)
outreg2 using ${dir_dest_tables}app_comp_dist.tex,append dec(2)
reg d_lhc dist_d_lhc tf_exp_wage tf_imp_wage tf_m_wage  lhc_st  if year==2001 , cluster(provgb)
outreg2 using ${dir_dest_tables}app_comp_dist.tex,append dec(2)
reg d_lhc dist_d_lhc dist_tf_exp_wage tf_exp_wage tf_imp_wage tf_m_wage  lhc_st  if year==2001 , cluster(provgb)
outreg2 using ${dir_dest_tables}app_comp_dist.tex,append dec(2)

sum tf_exp_wage_pv_1 dist_tf_exp_wage
sum d_lhc_pv_1 dist_d_lhc

***********************************************************************************************************
// Table C7. Competition between prefectures, other measures of proximity
***********************************************************************************************************

set more off
use ${dir_dest}2_main_regression.dta,clear
keep if year==2001
keep if lambda13<=.0548622
keep if d_l_gdppct!=.

set more off
reg d_lhc ind_d_lhc tf_exp_wage tf_imp_wage tf_m_wage  lhc_st  if year==2001 , cluster(provgb)
outreg2 using ${dir_dest_tables}app_comp_ind.tex,replace dec(2)
reg d_lhc pop_tf_exp_wage c.tf_exp_wage tf_imp_wage tf_m_wage  lhc_st  if year==2001 , cluster(provgb)
outreg2 using ${dir_dest_tables}app_comp_ind.tex,append dec(2)
reg d_lhc pop_d_lhc c.tf_exp_wage tf_imp_wage tf_m_wage  lhc_st  if year==2001 , cluster(provgb)
outreg2 using ${dir_dest_tables}app_comp_ind.tex,append dec(2)
reg d_lhc pop_d_lhc pop_tf_exp_wage c.tf_exp_wage tf_imp_wage tf_m_wage  lhc_st  if year==2001 , cluster(provgb)
outreg2 using ${dir_dest_tables}app_comp_ind.tex,append dec(2)
reg d_lhc gdp_tf_exp_wage c.tf_exp_wage tf_imp_wage tf_m_wage  lhc_st  if year==2001 , cluster(provgb)
outreg2 using ${dir_dest_tables}app_comp_ind.tex,append dec(2)
reg d_lhc gdp_d_lhc c.tf_exp_wage tf_imp_wage tf_m_wage  lhc_st  if year==2001 , cluster(provgb)
outreg2 using ${dir_dest_tables}app_comp_ind.tex,append dec(2)
reg d_lhc gdp_d_lhc gdp_tf_exp_wage c.tf_exp_wage tf_imp_wage tf_m_wage  lhc_st  if year==2001 , cluster(provgb)
outreg2 using ${dir_dest_tables}app_comp_ind.tex,append dec(2)

sum pop_tf_exp_wage gdp_tf_exp_wage
sum ind_d_lhc pop_d_lhc gdp_d_lhc

***********************************************************************************************************
// Table C8. Regulation changes and migrant flows, lagged, current, and lead
***********************************************************************************************************

use ${dir_dest}4_flow_or_reg.dta,clear

sum d_in_pct2005

set more off

reg d_in_pct2005 d_l_score1995 in_pct_st2005 l_totpop_st2005, cluster(provgb) /*-2*/
sum d_l_score1995
local mx=round(`r(mean)', 0.01) 
local sdx=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_flow_reg.tex,replace dec(2)  addtext(Mean x, `mx', Sd x, `sdx')
reg d_in_pct2005 d_l_score2000 in_pct_st2005 l_totpop_st2005, cluster(provgb) /*-1*/
sum d_l_score2000
local mx=round(`r(mean)', 0.01) 
local sdx=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_flow_reg.tex,append dec(2)    addtext(Mean x, `mx', Sd x, `sdx')
reg d_in_pct2005 d_l_score2005 in_pct_st2005 l_totpop_st2005, cluster(provgb) /*0*/
sum d_l_score2005
local mx=round(`r(mean)', 0.01) 
local sdx=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_flow_reg.tex,append dec(2)   addtext(Mean x, `mx', Sd x, `sdx')
reg d_in_pct2005 d_l_score2010 in_pct_st2005 l_totpop_st2005, cluster(provgb) /*1*/
sum d_l_score2010
local mx=round(`r(mean)', 0.01) 
local sdx=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_flow_reg.tex,append dec(2)   addtext(Mean x, `mx', Sd x, `sdx')


***********************************************************************************************************
// Table C9. Effects of changes in tariffs on exports and regulation changes on economic outcomes, OLS
***********************************************************************************************************
set more off
use ${dir_dest}2_main_regression.dta,clear
global trade_shock tf_exp_wage tf_imp_wage tf_m_wage
keep if year==2001
keep if lambda13<=.0548622
keep if d_l_gdppct!=.
*Table 4. Wage, total employment and GDP
sum d_l_wage d_l_gdppct d_l_totemp  if year==2001 & tf_exp_wage!=.

set more off
reg d_l_wage $trade_shock l_wage_st l_totpop_st if year==2001, cluster(provgb)
outreg2 using ${dir_dest_tables}app_econ_ols.tex,replace dec(2)  
reg d_l_wage d_lhc l_wage_st l_totpop_st if year==2001, cluster(provgb)
outreg2 using ${dir_dest_tables}app_econ_ols.tex,append dec(2)  
reg d_l_wage $trade_shock d_lhc l_wage_st l_totpop_st  if year==2001, cluster(provgb)
outreg2 using ${dir_dest_tables}app_econ_ols.tex,append dec(2) 
reg d_l_gdppct $trade_shock l_gdppct_st l_totpop_st if year==2001, cluster(provgb)
outreg2 using ${dir_dest_tables}app_econ_ols.tex,append dec(2)  
reg d_l_gdppct d_lhc l_gdppct_st l_totpop_st if year==2001, cluster(provgb)
outreg2 using ${dir_dest_tables}app_econ_ols.tex,append dec(2)  
reg d_l_gdppct $trade_shock d_lhc l_gdppct_st l_totpop_st if year==2001, cluster(provgb)
outreg2 using ${dir_dest_tables}app_econ_ols.tex,append dec(2)  
reg d_l_totemp $trade_shock l_totemp_st l_totpop_st if year==2001, cluster(provgb)
outreg2 using ${dir_dest_tables}app_econ_ols.tex,append dec(2)  
reg d_l_totemp d_lhc l_totemp_st l_totpop_st if year==2001, cluster(provgb)
outreg2 using ${dir_dest_tables}app_econ_ols.tex,append dec(2)  
reg d_l_totemp $trade_shock d_lhc l_totemp_st l_totpop_st if year==2001, cluster(provgb)
outreg2 using ${dir_dest_tables}app_econ_ols.tex,append dec(2)  

***********************************************************************************************************
// Table C10. Effects of changes in tariffs on exports and regulation changes on economic outcomes, IV
***********************************************************************************************************


set more off
use ${dir_dest}2_main_regression.dta,clear
keep if year==2001
keep if lambda13<=.0548622
keep if d_l_gdppct!=.


sum d_in_pct d_l_wage d_l_gdppct d_l_totemp
set more off
reg d_lhc tf_exp_wage tf_imp_wage tf_m_wage ngrrate lhc_st,cluster(provgb)
outreg2 using ${dir_dest_tables}app_iv.tex,replace dec(2) 
reg d_in_pct tf_exp_wage tf_imp_wage tf_m_wage d_lhc ngrrate in_pct_st l_totpop_st,cluster(provgb)
outreg2 using ${dir_dest_tables}app_iv.tex,append dec(2) 
reg d_in_pct tf_exp_wage tf_imp_wage tf_m_wage d_lhc in_pct_st l_totpop_st,cluster(provgb)
outreg2 using ${dir_dest_tables}app_iv.tex,append dec(2) 
est store r1
ivreg2 d_in_pct tf_exp_wage tf_imp_wage tf_m_wage (d_lhc=ngrrate) in_pct_st l_totpop_st,first cluster(provgb)
outreg2 using ${dir_dest_tables}app_iv.tex,append dec(2) 
est store r2
reg d_l_wage tf_exp_wage tf_imp_wage tf_m_wage d_lhc l_wage_st l_totpop_st ,cluster(provgb)
outreg2 using ${dir_dest_tables}app_iv.tex,append dec(2) 
est store r3
ivreg2 d_l_wage tf_exp_wage tf_imp_wage tf_m_wage (d_lhc=ngrrate) l_wage_st l_totpop_st,first cluster(provgb)
outreg2 using ${dir_dest_tables}app_iv.tex,append dec(2) 
est store r4
reg d_l_gdppct tf_exp_wage tf_imp_wage tf_m_wage d_lhc l_gdppct_st l_totpop_st ,cluster(provgb)
outreg2 using ${dir_dest_tables}app_iv.tex,append dec(2) 
est store r5
ivreg2 d_l_gdppct tf_exp_wage tf_imp_wage tf_m_wage (d_lhc=ngrrate) l_gdppct_st l_totpop_st,first cluster(provgb)
outreg2 using ${dir_dest_tables}app_iv.tex,append dec(2) 
est store r6
reg d_l_totemp tf_exp_wage tf_imp_wage tf_m_wage d_lhc l_totemp_st l_totpop_st ,cluster(provgb)
outreg2 using ${dir_dest_tables}app_iv.tex,append dec(2) 
est store r7
ivreg2 d_l_totemp tf_exp_wage tf_imp_wage tf_m_wage (d_lhc=ngrrate) l_totemp_st l_totpop_st,first cluster(provgb)
outreg2 using ${dir_dest_tables}app_iv.tex,append dec(2) 
est store r8

hausman r2 r1
hausman r4 r3
hausman r6 r5
hausman r8 r7

***********************************************************************************************************
// Table C11. The relationship between changes in tariffs on exports (2001–2007) and migrant flow in subcategories (2000–2010)
***********************************************************************************************************

set more off
use ${dir_dest}2_main_regression.dta,clear
keep if year==2001
keep if lambda13<=.0548622
keep if d_l_gdppct!=.

set more off
reg d_why_busi tf_exp_wage tf_imp_wage tf_m_wage l_why_busi_st l_totpop_st , cluster(provgb)
sum d_why_busi
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_migr_sub1.tex,replace dec(2)    addtext(Mean y, `my', Sd y, `sdy')
reg d_why_along tf_exp_wage tf_imp_wage tf_m_wage l_why_along_st l_totpop_st , cluster(provgb)
sum d_why_along
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_migr_sub1.tex,append dec(2)    addtext(Mean y, `my', Sd y, `sdy') 
reg d_why_marry tf_exp_wage tf_imp_wage tf_m_wage l_why_marry_st l_totpop_st, cluster(provgb)
sum d_why_marry
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_migr_sub1.tex,append dec(2)     addtext(Mean y, `my', Sd y, `sdy')
reg d_why_other tf_exp_wage tf_imp_wage tf_m_wage l_why_other_st l_totpop_st, cluster(provgb)
sum d_why_other
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_migr_sub1.tex,append dec(2)     addtext(Mean y, `my', Sd y, `sdy')
reg d_move_less3 tf_exp_wage tf_imp_wage tf_m_wage l_move_less3_st l_totpop_st, cluster(provgb)
sum d_move_less3
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_migr_sub1.tex,append dec(2)     addtext(Mean y, `my', Sd y, `sdy')
reg d_move_more3 tf_exp_wage tf_imp_wage tf_m_wage l_move_more3_st l_totpop_st, cluster(provgb)
sum d_move_more3
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_migr_sub1.tex,append dec(2)     addtext(Mean y, `my', Sd y, `sdy')
reg d_edu_less12 tf_exp_wage tf_imp_wage tf_m_wage l_edu_less12_st l_totpop_st, cluster(provgb)
sum d_edu_less12
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_migr_sub1.tex,append dec(2)    addtext(Mean y, `my', Sd y, `sdy') 
reg d_edu_more12 tf_exp_wage tf_imp_wage tf_m_wage l_edu_more12_st l_totpop_st, cluster(provgb)
sum d_edu_more12
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}app_migr_sub1.tex,append dec(2)     addtext(Mean y, `my', Sd y, `sdy')

***********************************************************************************************************
// Table C12. The relationship between changes in regulations (2001–2007) and migrant flow in subcategories (2000–2010)
***********************************************************************************************************

set more off
use ${dir_dest}2_main_regression.dta,clear
keep if year==2001
keep if lambda13<=.0548622
keep if d_l_gdppct!=.

set more off
reg d_why_busi d_lhc l_why_busi_st l_totpop_st , cluster(provgb)
outreg2 using ${dir_dest_tables}app_migr_sub2.tex,replace dec(2) 
reg d_why_along d_lhc l_why_along_st l_totpop_st , cluster(provgb)
outreg2 using ${dir_dest_tables}app_migr_sub2.tex,append dec(2) 
reg d_why_marry d_lhc l_why_marry_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_migr_sub2.tex,append dec(2) 
reg d_why_other d_lhc l_why_other_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_migr_sub2.tex,append dec(2) 
reg d_move_less3 d_lhc l_move_less3_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_migr_sub2.tex,append dec(2) 
reg d_move_more3 d_lhc l_move_more3_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_migr_sub2.tex,append dec(2) 
reg d_edu_less12 d_lhc l_edu_less12_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_migr_sub2.tex,append dec(2) 
reg d_edu_more12 d_lhc l_edu_more12_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_migr_sub2.tex,append dec(2) 


***********************************************************************************************************
// Table C13. The effects of changes in tariffs on exports (2001–2007) and regulation changes (2001–2007) on emigration (2000–2010)
***********************************************************************************************************
set more off
use ${dir_dest}2_main_regression.dta,clear
keep if year==2001
keep if lambda13<=.0548622
keep if d_l_gdppct!=.

sum d_out_pct d_pop_hk_nres if tf_exp_wage!=. & year==2001
set more off
reg d_out_pct  tf_exp_wage tf_imp_wage tf_m_wage out_pct_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_emi.tex,replace dec(2) 
reg d_out_pct d_lhc out_pct_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_emi.tex,append dec(2)  
reg d_out_pct tf_exp_wage tf_imp_wage tf_m_wage  d_lhc out_pct_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_emi.tex,append dec(2)  
reg d_pop_hk_nres  tf_exp_wage tf_imp_wage tf_m_wage l_pop_hk_nres_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_emi.tex,append dec(2)  
reg d_pop_hk_nres d_lhc l_pop_hk_nres_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_emi.tex,append dec(2)  
reg d_pop_hk_nres  tf_exp_wage tf_imp_wage tf_m_wage d_lhc l_pop_hk_nres_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_emi.tex,append dec(2)  

***********************************************************************************************************
// Table C14. Interaction effects of migrant supply and migrant demand
***********************************************************************************************************

set more off
use ${dir_dest}2_main_regression.dta,clear
keep if year==2001
keep if lambda13<=.0548622
keep if d_l_gdppct!=.

set more off
reg d_in_pct c.popfarm_w d_lhc c.tf_exp_wage tf_imp_wage tf_m_wage in_pct_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_supply.tex,replace dec(2)
reg d_in_pct d_lhc c.popfarm_w##c.tf_exp_wage tf_imp_wage tf_m_wage in_pct_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_supply.tex,append dec(2)
reg d_in_pct c.popfarm_w##c.d_lhc c.tf_exp_wage tf_imp_wage tf_m_wage in_pct_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_supply.tex,append dec(2)
reg d_in_cnty c.l_popfarm_st d_lhc c.tf_exp_wage tf_imp_wage tf_m_wage l_in_cnty_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_supply.tex,append dec(2)
reg d_in_cnty d_lhc c.l_popfarm_st##c.tf_exp_wage tf_imp_wage tf_m_wage l_in_cnty_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_supply.tex,append dec(2)
reg d_in_cnty c.l_popfarm_st##c.d_lhc c.tf_exp_wage tf_imp_wage tf_m_wage l_in_cnty_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_supply.tex,append dec(2)
reg d_in_city c.l_popfarm_pv d_lhc c.tf_exp_wage tf_imp_wage tf_m_wage l_in_city_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_supply.tex,append dec(2)
reg d_in_city d_lhc c.l_popfarm_pv##c.tf_exp_wage tf_imp_wage tf_m_wage l_in_city_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_supply.tex,append dec(2)
reg d_in_city c.l_popfarm_pv##c.d_lhc c.tf_exp_wage tf_imp_wage tf_m_wage l_in_city_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}app_supply.tex,append dec(2)

sum d_in_pct if popfarm_w!=.
sum d_in_cnty d_in_city
